//
//  SearchRecommendCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/30.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "SearchRecommendCell.h"

@implementation SearchRecommendCell{
    UIImageView *headImage;
    QXLable *labName;
    UIButton *btnFocus;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        headImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar"]];
        headImage.layer.masksToBounds=YES;
        headImage.layer.cornerRadius=20;
        [self.contentView addSubview:headImage];
        [headImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(10);
            make.top.equalTo(self.contentView).with.offset(10);
            make.bottom.equalTo(self.contentView).with.offset(-10);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        
        labName=[[QXLable alloc]init];
//        labName.text=@"一只安静的哈士奇";
        labName.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:labName];
        [labName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(headImage.mas_right).with.offset(5);
            make.height.mas_equalTo(@30);
        }];
        
        btnFocus =[[UIButton alloc]init];
        btnFocus.layer.masksToBounds=YES;
        btnFocus.layer.borderWidth=1.0;
        [btnFocus.titleLabel setFont:[UIFont systemFontOfSize:9]];
        [btnFocus addTarget:self action:@selector(onclickFocus) forControlEvents:UIControlEventTouchUpInside];
        btnFocus.layer.cornerRadius=2.0;
        [self.contentView addSubview:btnFocus];
        [btnFocus mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.right.equalTo(self.contentView);
            make.right.equalTo(self.contentView).with.offset(-20);
            make.size.mas_equalTo(CGSizeMake(35, 20));
        }];
    }
    return self;
}

- (void)onclickFocus{
    if (self.focusBlock) {
        self.focusBlock(self.model);
    }
}

- (void)setModel:(ExpertsHotModel *)model{
    _model=model;
    [headImage sd_setImageWithURL:[NSURL URLWithString:model.Avater] placeholderImage:[UIImage imageNamed:@"avatar"]];
    labName.text=model.Name;
    if (model.isFollow) {
        [btnFocus setTitle:@"已关注" forState:UIControlStateNormal];
        [btnFocus setTitleColor:DEFAULTTEXTGRAYCOLOR forState:UIControlStateNormal];
        btnFocus.layer.borderColor=DEFAULTTEXTGRAYCOLOR.CGColor;
    }else{
        [btnFocus setTitle:@"关注" forState:UIControlStateNormal];
        [btnFocus setTitleColor:NAVCOLOR forState:UIControlStateNormal];
        btnFocus.layer.borderColor=NAVCOLOR.CGColor;
    }
}
@end
